function relod() {
    layui.use('table', function() {
        var table = layui.table;
        table.reload('test', {
            page: {
                curr: 1 //重新从第一页开始
            }, where: {
                startTime: $("#test1").val(),
                endTime: $("#test2").val(),
                pid: $("#cgd").val(),
                status: 3,
                payStatus: 1
            }
        })
    })
}
layui.use('form', function(){
    var form = layui.form;

    //监听提交
    form.on('submit(formDemo)', function(data){
        layer.msg(JSON.stringify(data.field));
        return false;
    });
});
layui.use('table', function(){
    var table = layui.table;
    table.render({
        elem: '#test'
        ,url:'htz/purchaseOrder/all'
        ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
        ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
            title: '提示'
            ,layEvent: 'LAYTABLE_TIPS'
            ,icon: 'layui-icon-tips'
        }]
        ,title: '用户数据表'
        ,parseData: function(res) { //res 即为原始返回的数据
            return {
                "code": 0, //解析接口状态
                "msg": "", //解析提示文本
                "count": res.obj.total, //解析数据长度
                "data": res.obj.list //解析数据列表
            };
        }
        ,cols: [[
            {type: 'checkbox', fixed: 'left',width:40}
            ,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
            ,{field:'purchaseOrderCode', title:'采购单Id', width:120,unresize: true, sort: true}
            ,{field:'sourceId', title:'上游单号', width:120, templet: function(res){
                    if (res.sourceId==null){
                        return "无"
                    }
                    return res.sourceId
                }}
            ,{field:'createDate', title:'生成采购单时间', width:180}
            ,{field:'purchaseOrderCost', title:'预计总金额', width:120}
            ,{field:'status', title:'采购单状态', width:120,templet:function (res) {
                    switch (res.status) {
                        case 1:
                            return "新录入";
                        case 2:
                            return "待审核";
                        case 3:
                            return "审核通过";
                        case 4:
                            return "审核不通过";
                        case 5:
                            return "采购单进行中";
                        case 6:
                            return "已完成";
                    }
                }}
            ,{field:'purchaserName', title:'采购员姓名', width:120}
            ,{field:'auditName', title:'审核人姓名', width:120,templet:function (res) {
                    if (res.auditName==''||res.auditName==null){
                        return "无"
                    }
                    return res.auditName;
                }}
            ,{field:'type', title:'采购单类型', width:120,templet:function (data) {
                    switch (data.type) {
                        case 1:
                            return "新品采购";
                        case 2:
                            return "补货";
                    }
                }}
            ,{field:'payStatus', title:'采购单类型', width:120,templet:function (data) {
                    switch (data.payStatus) {
                        case 1:
                            return "未付款";
                        case 2:
                            return "已付款";
                    }
                }}
            ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:180}
        ]]
        ,page: true
        ,where: {
            payStatus: 1,
            status: 3
        }
    });

    //头工具栏事件
    table.on('toolbar(test)', function(obj){
        var checkStatus = table.checkStatus(obj.config.id);
        switch(obj.event){
            case 'getCheckData':
                var data = checkStatus.data;
                layer.alert(JSON.stringify(data));
                break;
            case 'getCheckLength':
                var data = checkStatus.data;
                layer.msg('选中了：'+ data.length + ' 个');
                break;
            case 'isAll':
                layer.msg(checkStatus.isAll ? '全选': '未全选');
                break;

            //自定义头工具栏右侧图标 - 提示
            case 'LAYTABLE_TIPS':
                layer.alert('这是工具栏右侧自定义的一个图标按钮');
                break;
        };
    });

    //监听行工具事件
    table.on('tool(test)', function(obj){
        var data = obj.data;
        //console.log(obj)
        if(obj.event === 'del'){
            layer.confirm('真的删除行么', function(index){
                obj.del();
                layer.close(index);
            });
        } else if(obj.event === 'edit'){
            layer.prompt({
                formType: 2
                ,value: data.email
            }, function(value, index){
                obj.update({
                    email: value
                });
                layer.close(index);
            });
        }else if (obj.event==='pay'){
            layer.confirm('<h3 style=\'text-align: center;color: #0000FF\'>是否收款</h3>',{
                btn:['确认收款','取消收款']
            },function (index,layero) {
                layer.msg("收款成功",{icon:1})
            },function (index) {
                layer.msg("收款失败",{icon:2})
            })
        } else if(obj.event === 'view'){
            layer.open({
                type: 2,
                area: ['600px','310px'],
                content: 'purchase_pay_detail.html', //这里content是一个普通的String
                success:function (layero,index) {
                    var iframe = window['layui-layer-iframe'+index]
                    iframe.relod(data);
                }
            });
        }
    });
});